Skip to content

Switch the TUI stack to charm.land v2 (bubbletea, bubbles, lipgloss, huh) - #7742

Open
pietern wants to merge 4 commits into
pietern/charm-v2/03c-key-changesfrom
pietern/charm-v2/04-swap
Open

pietern wants to merge 4 commits into
pietern/charm-v2/03c-key-changesfrom
pietern/charm-v2/04-swap

Conversation

@pietern

@pietern pietern commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Moves the TUI stack to charm.land/bubbletea/v2, bubbles/v2, lipgloss/v2 and huh/v2, and fixes three things the swap would otherwise regress. The last commit of the stack; the earlier PRs carry the rest of the work.

The swap

  • Models handle key events through teainput; tea.HideCursor is gone (bubbletea hides the cursor while a program runs), so the select modes golden loses one ?25 reset.
  • Colour: each program gets its stream's profile (WithColorProfile, floored at ANSI for template helpers). colorDepth still uses termenv, so TERM unset, CI, CLICOLOR=0, TERM=screen and tmux+truecolor keep v1's depth.
  • LogString gets the same floor. v2's Renderer.Writer always downsamples, so with CI or CLICOLOR=0 on a terminal it would strip the basic colors cmdio's helpers emit, which v1 passed through (cmdio: strip styles from LogString output on a color-less stderr #7738 promises to keep them).
  • selftest tui colors --lipgloss --stream stdout|stderr writes its swatches through the renderer's writer. v2 styles render full color by themselves, so without it NO_COLOR and CLICOLOR=0 did not apply to them.
  • tableview.RunWithOptions sends its window size with tea.WithWindowSize, so the first frame is drawn at that size (v2 renders before a sent message lands).
  • Dark background: the appkit theme is a huh.ThemeFunc, and huh resolves the background itself.
  • cmd/selftest/tui ports to v2 (keys prints the raw v2 key next to the decoded event; profile and huh read the background through lipgloss.HasDarkBackground).

Fix 1: leftover terminal replies

bubbletea v2 sends queries at startup (DECRQM 2026 and 2027, kitty keyboard flags). A program that quits before the terminal answers left those answers for the shell prompt. cmdio.NewTeaProgram now defers the quit, on a terminal only, until the terminal answers a cursor position request sent at quit time. Terminals answer in order, so the earlier answers have been read by then.

This applies to every quit of a guarded program (prompts, selection lists, the pager, the table viewer and databricks air's list), not only when replies are missing. Each quit costs one terminal round trip: milliseconds locally, one RTT over SSH. If the terminal never answers, the quit goes ahead after 2 s. Keys typed or pasted during the wait are discarded, because the model has already quit.

Fix 2: Shift+Enter

v2 enables the kitty keyboard protocol, so terminals that report Shift+Enter separately (Ghostty, kitty, WezTerm) send it as its own key. teainput.KeyName maps shift+enter to enter, so prompts and selection lists submit on it.

Fix 3: huh forms

Forms go through cmdio.RunHuhField and cmdio.RunHuhForm (19 call sites in libs/apps/prompt, cmd/apps, cmd/aitools, and the selftest probe). They run with the context's input, stderr and the stderr colour profile. huh's WithProgramOptions replaces its defaults, so input and output are passed explicitly. Not covered: the reply guard. It has to inject a message if the terminal never answers, and a huh program does not expose Send, so a missed answer would hang the quit. A huh form can still leave a late reply on the shell prompt after a quick quit; that is open.

Changelog: .nextchanges/cli/kitty-keyboard.md, shift-enter.md and terminal-replies.md. terminal-replies.md also states the huh limitation.

Why

v2 changes the key, cursor, colour and program APIs; the swap has to keep v1's visible behaviour except where a change is deliberate and pinned. The three fixes address regressions that the swap would otherwise ship.

Tests

  • go build ./..., golangci-lint (0 issues), gofmt clean.
  • TERM=xterm-256color go test -race -count=3 ./libs/cmdio/... passes.
  • Unit tests for libs/tableview, libs/apps/..., cmd/air, cmd/apps, cmd/fs, cmd/aitools, cmd/selftest/..., internal/build pass.
  • The full acceptance suite (go test ./acceptance/...) passes.
  • New unit tests: TestLogStringKeepsHelperColorsWhenProfileIsAscii (CI and CLICOLOR=0), TestRunHuhFieldUsesContextIO, and the reply guard tests (the timeout is stopped once the cursor report arrives).
  • GOOS=windows go vet ./libs/cmdio/... and GOOS=darwin go vet ./libs/cmdio/... pass.
  • PTY smoke test of each selftest command built from this branch (keys, profile, colors --lipgloss, pager, table, huh, prompt, select, spinner): all exit 0 with the expected output.

Golden changes (pins), against the previous branch

Fourteen pin groups change, all intended:

  • TestModesPin_{Prompt,Select,Pager}/{enter,ctrl-c}, TestModesPin_Spinner: v2 sets modifyOtherKeys 2 and kitty push 1 and undoes both on exit; the mouse-mode resets are gone (v2 never sets those modes); select no longer toggles ?25 twice.
  • TestKeysPin_{Prompt,Select}ShiftEnter/{kitty,modifyOtherKeys}: Shift+Enter submits (Value: xy, z left unread; the select clears its screen).
  • TestKeysPin_PromptBracketedPasteWithNewline: the screen keeps ✔ Value: a above b█.
  • TestQueriesPin_PromptQuitBeforeReplies and TestQueriesPin_SelectQuitBeforeReplies: pipes never install the guard, so these pins now record v2's queries and the unguarded leftover.
  • TestQueriesPin_PromptTerminalAnswersAtOnce: v2's three startup queries are in the golden.
  • TestQueriesPin_PromptUnsolicitedBackgroundReply: the late OSC 11 reply is consumed; the value is ab, not ab11;rgb:….
  • New: TestQueriesPin_PromptQuitBeforeRepliesTTY (stdin poses as a terminal through the new termtest StdinTTY option). The guard holds the quit for the cursor report; leftover is (none).

Unchanged and passing: the pager's first-page spinner pins (TestPagerPin_SpinnerDuringFirstPage and TestPagerPin_EnterWhileFirstPageLoads still show several frames), the colour pins, and the Alt pins from #7741. The colour pins cover cmdio's color decisions on a pipe, not a real terminal's depth; see the manual colour check.

Test-only changes

  • libs/cmdio/teaprogram_test.go: TestNewTeaProgramGuardsTerminalInput runs NewTeaProgram with a faked terminal. It finishes in about 100 ms.
  • Test helpers now strip escape sequences before counting pager rows or comparing row text (v2 writes its queries into the stream).

Known issues

  • Spinner and LogString interleave on v2. LogString writes to the terminal while a spinner's renderer is drawing, so the first frame can land before the log line (*spinner started, or * Workingspinner started). Under eight parallel -race copies of TestColorPin_Spinner with -count=25, v2 failed 13 times across 6 of 8 copies; v1 failed zero times. Fixing it means routing LogString through the active program, which has a message-loss window at teardown. Not in this PR.
  • huh forms skip the reply guard (Fix 3). After a very quick quit, a form in databricks apps or databricks aitools can still leave a terminal answer such as ^[[?2026;2$y at the shell prompt. This is a known limitation of this PR, documented on cmdio.RunHuhField and in the changelog.

Manual checks on real terminals

Run each with the v1 build (main, or #7688 for the selftest tui commands) and with this build.

  • Shift+Enter (Ghostty, kitty, WezTerm): databricks selftest tui prompt, type xy, Shift+Enter, z, Enter. v2: Entered: xy (Shift+Enter submits). Record what v1 prints: without the kitty keyboard protocol these terminals usually send a plain Enter.
  • Quick quit leftovers (SSH with about 150 ms RTT, or nested tmux): databricks selftest tui prompt, type ab and Enter at once, then look at the shell prompt. Both: nothing left over, such as ^[[?2026;2$y. v1 sends no such queries; v2 waits for the answers before it exits.
  • Terminal signal: databricks selftest tui prompt &, kill -TERM %1, then stty -a in the shell. Open issue: v2 leaves kitty keyboard and modifyOtherKeys on until reset, as v1 leaves raw mode.
  • Colour: databricks selftest tui profile and databricks selftest tui colors --lipgloss, with TERM unset, CI=1, CLICOLOR=0, TERM=screen, and tmux with COLORTERM=truecolor. The depth must match v1's. With both stdout and stderr on a terminal, CI=1 databricks selftest tui colors must show the helper colors, as on v1.
  • Startup: databricks selftest tui prompt under a terminal that does not answer OSC 11 (for example script): the prompt should appear at once, and typed keys are kept.
  • Pager: databricks selftest tui pager --items 30 --delay-first 4s: the spinner animates during the first fetch, then the first page and the prompt.
  • Table: databricks selftest tui table --rows 50, /, type text, Alt+F, paste, Enter, q: no alt+f or pasted [text] in the search.
  • huh: databricks selftest tui huh --field confirm, on a dark and a light background: dark_background and the blurred-button colour match the background.

This pull request and its description were written by Isaac.

@pietern
pietern force-pushed the pietern/charm-v2/04-swap branch from e70fa46 to 93defd8 Compare November 17, 2026 22:30
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 2c519b9

Run: 44344046335

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 19 18:10
💚​ aws-windows-latest-4core-16gb 1 274 17 11:35
💚​ azure linux-2core-8gb 1 271 19 17:10
💚​ azure-windows-latest-4core-16gb 1 273 17 12:24
💚​ gcp linux-2core-8gb 1 272 19 14:10
💚​ gcp-windows-latest-4core-16gb 1 274 17 9:17
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 45 slowest tests (at least 2 minutes):
duration env testname
7:56 gcp-windows-latest-4core-16gb TestAccept
5:51 aws linux-2core-8gb TestFilerRecursiveDelete/workspace_files_extensions
5:25 aws linux-2core-8gb TestImportDirWithOverwriteFlag
5:19 gcp linux-2core-8gb TestFilerRecursiveDelete/workspace_files
5:01 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
4:55 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsStat
4:39 azure linux-2core-8gb TestExportDir
4:20 azure-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files
4:14 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
4:05 aws-windows-latest-4core-16gb TestFilerReadWrite/workspace_files_extensions
3:41 aws linux-2core-8gb TestFilerRecursiveDelete/workspace_files
3:38 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsRead
3:28 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsDelete
3:16 azure linux-2core-8gb TestExportWithFileFlag
3:16 azure-windows-latest-4core-16gb TestExportDir
3:15 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
3:01 azure-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files_extensions
3:00 azure-windows-latest-4core-16gb TestSyncIncrementalFileSync
2:57 gcp linux-2core-8gb TestExportDir
2:56 azure-windows-latest-4core-16gb TestImportDir
2:54 azure-windows-latest-4core-16gb TestFilerReadWrite/workspace_files
2:54 aws linux-2core-8gb TestFilerReadWrite/workspace_files_extensions
2:53 gcp linux-2core-8gb TestFilerReadDir/workspace_files_extensions
2:53 aws-windows-latest-4core-16gb TestFilerRecursiveDelete/workspace_files
2:43 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsStat
2:39 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
2:37 aws linux-2core-8gb TestFilerReadWrite/workspace_files
2:35 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsDelete
2:35 aws-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
2:31 aws-windows-latest-4core-16gb TestSyncIncrementalFileSync
2:27 gcp-windows-latest-4core-16gb TestFilerWorkspaceNotebook/sqlNb.sql
2:26 gcp-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir
2:20 azure-windows-latest-4core-16gb TestImportDirDoesNotOverwrite
2:20 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsStat
2:19 aws-windows-latest-4core-16gb TestImportDirDoesNotOverwrite
2:14 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsRead
2:13 aws linux-2core-8gb TestExportDir
2:12 aws linux-2core-8gb TestFilerWorkspaceNotebook/sqlNb.sql
2:11 gcp linux-2core-8gb TestImportDirDoesNotOverwrite
2:11 azure linux-2core-8gb TestFilerWorkspaceNotebook/pythonJupyterNb.ipynb
2:08 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsStat
2:06 gcp-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsRead
2:04 azure linux-2core-8gb TestImportDirWithOverwriteFlag
2:03 azure linux-2core-8gb TestSyncFullFileSync
2:02 azure-windows-latest-4core-16gb TestFilerWorkspaceFilesExtensionsReadDir

@pietern
pietern added this pull request to stack #7754 November 18, 2026 08:35
@pietern

pietern commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/review

Comment thread libs/cmdio/teaprogram.go Outdated
g.waiting = true
g.quit = msg
go g.send(tea.RequestCursorPosition())
time.AfterFunc(g.wait, func() { g.send(replyGuardTimeout{}) })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time.AfterFunc timer is not stopped when the cursor report arrives and releases the guard at line 81. After the program exits, the timer fires and calls p.Send(replyGuardTimeout{}) on a completed program. Saving the *time.Timer on the struct and calling Stop() in the release branch would avoid the stale callback. Can we add a timer field and stop it at line 81?

@pietern
pietern force-pushed the pietern/charm-v2/04-swap branch from 93defd8 to 60a6b63 Compare November 18, 2026 13:07
@github-actions github-actions Bot added Dependencies Pull requests that update a dependency file AIR Databricks AI Runtime CLI aitools AI tools (databricks aitools) related changes labels Nov 18, 2026
@pietern
pietern force-pushed the pietern/charm-v2/04-swap branch from 60a6b63 to 4b39c09 Compare November 18, 2026 15:55
@pietern
pietern force-pushed the pietern/charm-v2/04-swap branch from 4b39c09 to 2c519b9 Compare November 18, 2026 16:08
@pietern

pietern commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/review

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at 2c519b9. Each finding was verified against the code.

Not ready yet: part of the automated review did not complete.

This PR migrates the TUI stack from charmbracelet v1 to charm.land v2 (bubbletea, bubbles, lipgloss, huh) and addresses three regressions the swap would otherwise introduce: leftover terminal replies, Shift+Enter handling, and huh form plumbing. The migration is thorough, with extensive test updates, golden file changes, and a new reply guard mechanism. Two minor improvements survived verification.

Comment thread libs/cmdio/teaprogram.go Outdated
g.waiting = true
g.quit = msg
go g.send(tea.RequestCursorPosition())
time.AfterFunc(g.wait, func() { g.send(replyGuardTimeout{}) })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The time.AfterFunc timer is never stopped when CursorPositionMsg arrives before the timeout. Every normal program quit leaves a sleeping goroutine for up to replyWait (2 s) that then calls g.send on a finished program. The filter swallows it and p.Send on a stopped program is a no-op, so this is harmless today, but storing the *time.Timer and calling Stop() inside the CursorPositionMsg branch (line 81, where g.released is set) would clean it up.

Comment thread libs/cmdio/huh.go
@@ -0,0 +1,41 @@
package cmdio

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] huh.go exports RunHuhField and RunHuhForm (19 call sites), but there is no huh_test.go. The testing rule in .agents/rules/testing.md asks for a corresponding test file for each source file. Even though the functions are thin, a unit test covering huhProgramOptions (e.g. verifying it picks up the context's input and stderr, and falls back to os.Stdin/os.Stderr when cmdIO is nil) would pin the wiring.

pietern and others added 4 commits November 23, 2026 15:45
…huh)

Moves the CLI's TUI code to charm.land/bubbletea/v2, bubbles/v2,
lipgloss/v2 and huh/v2, with the behaviour that v1 gave callers kept or
deliberately changed and pinned.

Swap
- Models handle key events through teainput; tea.HideCursor is gone
  (Bubble Tea hides the cursor while a program runs), so the select
  modes golden loses one "?25 reset".
- Color: the program's profile comes from the stream's cmdio.Renderer
  (WithColorProfile), floored at ANSI for template helpers, so
  TERM unset, CI and CLICOLOR=0 keep v1's depth.
- tableview.RunWithOptions sends its window size with tea.WithWindowSize,
  so the first frame is drawn at that size.
- cmd/selftest/tui ports to v2: keys prints the message and the decoded
  event side by side; profile and huh read the background through
  lipgloss.HasDarkBackground.

Quit guard
- cmdio.NewTeaProgram defers quitting, on a terminal, until the terminal
  answers the cursor position request sent at quit time. Terminals answer
  in order, so the answers to the startup queries are read before the
  program exits, and nothing is left at the shell prompt. The wait is
  bounded at 2 s.

Shift+Enter
- teainput.KeyName reports shift+enter as enter, for terminals that
  enable the kitty keyboard protocol.

huh
- Forms go through cmdio.RunHuhField or RunHuhForm, which run with the
  context's input, stderr, and the stderr color profile. huh's
  WithProgramOptions replaces its defaults, so the input and output are
  passed explicitly. The reply guard is not installed for huh: it needs
  to inject a message when the terminal does not answer, and a huh
  program does not expose Send.

Golden changes are listed in the stack PR body, one per behaviour.
Pins that need a terminal have a TTY variant (TestQueriesPin_PromptQuitBeforeRepliesTTY,
termtest StdinTTY), and TestNewTeaProgramGuardsTerminalInput covers the
constructor with a faked terminal.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The timeout no longer outlives a program that got its cursor report. The
timeout test drives the guard the way the event loop does instead of
calling filter from the timer goroutine.

Co-authored-by: Isaac <no-reply@databricks.com>
v2's Renderer.Writer always downsamples, so with CI or CLICOLOR=0 on a
terminal it stripped the basic ANSI colors cmdio's helpers emit, which v1
passed through. The selftest swatches now go through the renderer's writer
too, so NO_COLOR and CLICOLOR=0 apply to them.

Also narrow the kitty keyboard and terminal reply changelog entries to what
the change does.

Co-authored-by: Isaac <no-reply@databricks.com>
@pietern
pietern force-pushed the pietern/charm-v2/04-swap branch from dfd06f0 to ac1e69e Compare November 23, 2026 15:47
@pietern
pietern marked this pull request as ready for review November 23, 2026 15:49
@pietern
pietern requested a review from a team as a code owner November 23, 2026 15:49
@pietern
pietern requested review from a team and lennartkats-db as code owners November 23, 2026 15:49
@pietern

pietern commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/review

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at ac1e69e. Each finding was verified against the code.

Not ready yet: part of the automated review did not complete.

This PR moves the TUI stack to the charm.land v2 modules. It routes huh forms through cmdio.RunHuhField/RunHuhForm, adds a reply guard to NewTeaProgram so terminal answers don't leak to the shell, and maps Shift+Enter to Enter. The port looks careful and the pins back it up. One real behavior gap remains: the guard keeps delivering non-key messages after quit, so a draining pager keeps fetching and printing. Smaller items: two dead cmdIO fallbacks that break the no-speculative-fallback rule, a mismatched background probe in the selftest, and a changelog entry that lists too few TUIs.

Comment thread libs/cmdio/teaprogram.go
if _, ok := msg.(replyGuardTimeout); ok {
return nil
}
case tea.KeyPressMsg, tea.KeyReleaseMsg, tea.PasteMsg:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] While the quit is held, the guard drops only key and paste messages, so an in-flight batchMsg still reaches pagerModel.Update. Repro: press Enter to drain, then q. Because drainAll is still set, the pager prints the page and chains another m.fetch (pager.go:180-182), which is another API call. This repeats until the CPR answer arrives, so up to 2 s on a terminal that never answers. Before the guard, q ended the loop and the pending batch was dropped. Could the guard drop all model-bound messages once it is waiting? Or could the pager clear drainAll (or set a quitting flag) in handleKey before returning tea.Quit?

Comment thread libs/cmdio/huh.go
}

func huhProgramOptions(ctx context.Context) []tea.ProgramOption {
c, _ := ctx.Value(cmdIOKey).(*cmdIO)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The os.Stdin/os.Stderr fallback for a missing cmdIO can never run. A few lines later, SupportsColor(ctx, errW) calls fromContext, which panics when the context has no cmdIO. So a bare context panics instead of getting the defaults this branch suggests. AGENTS.md says to avoid speculative fallbacks and defensive nil checks, so can this use c := fromContext(ctx) and drop the defaults? The same applies to the ok && in paged_template.go:117: SupportsColor(ctx, out) a few lines above it already requires cmdIO, so fromContext(ctx).teaWindowSize would do.

Comment thread cmd/selftest/tui/huh.go
// The appkit theme is a huh.ThemeFunc, so its colours depend on the
// background, queried once here for the probe. The blurred button is
// the colour the theme picks for that background.
dark := lipgloss.HasDarkBackground(os.Stdin, os.Stdout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The form runs through RunHuhForm, which draws on the context's stderr, so huh resolves the ThemeFunc against the terminal on stderr. The probe queries os.Stdin/os.Stdout instead. With databricks selftest tui huh > out.txt, the stdout query can't reach a terminal and falls back to the default. The reported dark_background/blurred_button can then differ from what the form showed. Could the probe query stderr, the stream the form used? profile.go:42 has the same stdout query.

@@ -0,0 +1 @@
* Interactive prompts, selection lists and the pager enable the kitty keyboard protocol and modifyOtherKeys in terminals that support them, and turn them off again when they exit normally. A CLI killed by a signal such as SIGTERM can leave them enabled; run `reset` to restore the terminal. ([#7742](https://github.com/databricks/cli/pull/7742))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The entry names only prompts, selection lists and the pager. Every v2 program that reads input enables kitty keyboard and modifyOtherKeys, which includes the table viewer, the databricks air list and the huh forms. A user who hits the SIGTERM leftover from one of those won't find it described. Could it say "interactive terminal UIs" instead?

camielstee-db pushed a commit to camielstee-db/cli that referenced this pull request Nov 24, 2026
…atabricks#7884)

## Changes
Halve the agent rules: 66 KB → 33 KB of AGENTS.md + `.agents/rules/`.
The rules that are always loaded or loaded on every Go edit shrink the
most:

| Context loaded | Before | After |
|---|---|---|
| Always (AGENTS.md) | 12.2 KB | 6.1 KB |
| Editing a `.go` file (+ style-guide-go, comments) | 23.5 KB | 9.7 KB |
| Editing a `_test.go` file (+ testing) | 45.8 KB | 17.5 KB |
| Editing acceptance outputs (+ testing, auto-generated-files) | 38.5 KB
| 16.4 KB |

Skills are unchanged: they load only when invoked.

What was removed, and why:

- **Already enforced by `./task lint`** (the agent gets the same message
from the linter):
  - integer `range`, builtin `min`/`max` (modernize)
  - loop-variable capture (copyloopvar)
  - `os.Getenv`, `sync.Once` (forbidigo)
  - `context.Background()` (gorules)
  - `t.Context()` in tests (usetesting)
  - stdlib `log` (depguard)
  - `%w` wrapping (errorlint)
  - error-string punctuation (staticcheck ST1005)
  - copying `config.Config` (govet copylocks)
- **Wrong or stale:**
- `errors.As` was recommended, but forbidigo bans it (the tree has 0
`errors.As` calls vs 231 `errors.AsType`).
  - `isResourceGone` doesn't exist.
  - `libs/structpath` has moved to `libs/structs/structpath`.
  - "consult the Makefile": there is no Makefile.
- The `out.test.toml` old-format migration rule is dead: 0 files are
left in that format.
- "Use Python 3.11" also applied to `python/`, which supports `>=3.10`.
- The `databricks_template_schema.json` "reference" was an outdated copy
of dbt-sql's schema. It described a description convention the real file
no longer uses, and it had a typo. It is replaced by pointers to the
real templates and to `libs/jsonschema/extension.go`.
- template-versions.md hardcoded how many pins each template has. The
counts were wrong; the grep in the same rule is what the agent should
rely on.
- **Rules that produced wrong review feedback:**
- "Each source file should have a corresponding test file": 38% of
source files have none, and the rule contradicts acceptance-tests-first.
The reviewer bot used it to request tests for cobra wiring, and those
requests were ignored:
databricks#7688 (comment),
databricks#7742 (comment)
- "Place tests in the same package but with a `_test` suffix": 1050 test
files use the internal package and 231 use `_test`. The rule led to an
invented `_internal_test.go` convention that the author rejected:
databricks#7847 (comment)
- "Add `.databricks` to `Ignore`": `acceptance/script.cleanup` already
removes it. This produced a wrong `[blocking]` comment:
databricks#7846 (comment)
- "Define magic strings as named constants, even if short": reviewers
push back on single-use constants
(databricks#5844 (comment),
databricks#6204 (comment),
databricks#6149 (comment)).
- **Generic guidance current models already follow:**
  - return early
  - `switch` vs `if/else`
  - empty-struct context keys
  - table-driven tests
  - shared test constants
  - Go doc comment format
  - constructor parameter structs
  - "don't explain each test case in your responses"
  - debug prints (pr-checklist already covers them)
  - the GOOD/BAD preamble
- **Repetition:**
- `Cloud = true` runs locally too: this was explained 5 times and is now
explained once in AGENTS.md and once in testing.md.
  - `integration/` is deprecated: stated 4 times.
- "Don't edit generated outputs": stated 4 times across testing.md and
auto-generated-files.md.
- The `print_requests.py`/`jq` guidance was 3 overlapping rules and is
now 1.
- The long GOOD/BAD examples were dropped where the rule sentence
already says it.

Clarified:
- `os.Exit`: the rule now says how `TestMain` should exit. The bot had
suggested `os.Exit(m.Run())`, against this same rule:
databricks#7595 (comment)
- Comments: existing comments may be updated when your change makes them
wrong.

## Why
The rules were mostly mined from review history in
databricks#5078. That PR's follow-up
promised a slim-down that never came
(databricks#4882), and token cost had
already come up in review (databricks#6584).
Every byte of AGENTS.md and the Go/test rules is paid on most turns, and
rules that are wrong or that the linter already enforces either crowd
out the useful ones or become review noise. I checked the 98 comments
from review-oss-bot and the human pushback since 2026: the rules that
went wrong are the ones removed above. The acceptance-test rules that
came from real agent failures (`Cloud`, `EnvMatrix`, TOML dotted keys,
`musterr`/`errcode`, `print_requests.py`, testserver over `[[Server]]`,
GET-response projection) are kept, just shorter.

## Tests
`./task check-agents-setup` and `./task checks` pass. Every path,
helper, task and identifier still mentioned was checked against the
tree.

This pull request and its description were written by Isaac.

---------

Co-authored-by: Isaac <no-reply@databricks.com>

@pardis-beikzadeh-db pardis-beikzadeh-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review limited to cmd/air/.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIR Databricks AI Runtime CLI aitools AI tools (databricks aitools) related changes Dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants